#define _CRT_SECURE_NO_WARNINGS 1


class Solution {
public:
    int takeAttendance(vector<int>& records)
    {
        int n = records.size();
        int sum = 0;
        if (n >= 2)
            sum = (1 + records[n - 1]) * records[n - 1] / 2;
        else
        {
            for (auto e : records)
            {
                sum += e;
            }
        }

        for (int i = 0; i < n; i++)
        {
            sum -= records[i];
        }

        if (sum == 0)
        {
            if (records[0] == 1)
                sum = 0;
            else
                sum = n;
        }


        return sum;
    }
};

#include <iostream>
#include<vector>
using namespace std;


int main() {
    int n, m;
    while (cin >> n >> m) {
        vector<int> v(n + 1);
        for (int i = 1; i <= n; i++) {
            cin >> v[i];
        }

        vector<long long> dp(v.size());

        for (int i = 1; i < v.size(); i++) {
            dp[i] = dp[i - 1] + v[i];
        }
        for (int i = 0; i < m; i++) {
            int l, r;
            cin >> l >> r;
            cout << (dp[r] - dp[l - 1]) << endl;
        }
    }

    return 0;

}


#include <iostream>
#include<vector>
using namespace std;

int main()
{
    int row, col, num;
    while (cin >> row >> col >> num)
    {
        vector<vector<int>> matrix(row + 1, vector<int>(col + 1));
        for (int i = 1; i <= row; i++)
        {
            for (int j = 1; j <= col; j++)
            {
                cin >> matrix[i][j];
            }
        }

        vector<vector<long long>> dp(row + 1, vector<long long>(col + 1));
        for (int i = 1; i <= row; i++)
        {
            for (int j = 1; j <= col; j++)
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + matrix[i][j];
            }
        }
        for (int n = 0; n < num; n++)
        {
            int x1, x2, y1, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            cout << dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1] << endl;
        }
    }

    return 0;
}


class Solution {
public:
    int pivotIndex(vector<int>& nums)
    {
        int size = nums.size();
        vector<int> dppre(size);
        vector<int> dpaft(size);

        for (int i = 1; i < size; i++)
        {
            dppre[i] = dppre[i - 1] + nums[i - 1];
        }
        for (int i = size - 2; i >= 0; i--)
        {
            dpaft[i] = dpaft[i + 1] + nums[i + 1];
        }


        for (int i = 0; i < size; i++)
        {
            if (dppre[i] == dpaft[i]) return i;
        }

        return -1;
    }
};